# 数据可视化
from pyecharts.charts import Line
import pyecharts.options as opts


# --------数据可视化--------
class EnvData:
    def __init__(self):
        self.temperature = {}
        self.ph = {}
        self.tds = {}
        self.density_fish = {}
        self.density_ship = {}
        self.dict_env = {'density_ship', 'density_fish', 'ph', 'temperature', 'tds'}
        self.dict_navigate = ('speed', 'mileage', 'accelerate', 'endurance',
                              'pitch', 'yaw', 'roll',
                              'X', 'Y', 'Z', 'W')
        self.pitch = self.roll = self.yaw = None
        self.X = self.Y = self.Z = self.W = None
        self.speed = self.mileage = self.accelerate = self.endurance = None

    # 生成环境图表
    def gene_temp(self):
        (
            Line(  # 初始化配置
                init_opts=opts.InitOpts(
                    width='551px',
                    height='511px',
                    animation_opts=opts.AnimationOpts(animation=False))
            )
                .set_global_opts(  # 全局配置
                xaxis_opts=opts.AxisOpts(name='时间轴'),
                yaxis_opts=opts.AxisOpts(name='摄氏度/℃')
            )
                .add_xaxis(  # 添加x轴
                xaxis_data=list(self.temperature.keys())[-10:]
            )
                .add_yaxis(  # 添加y轴
                series_name='区域水温',
                y_axis=list(self.temperature.values())[-10:],
                symbol='emptyCircle',
                is_smooth=True
            )
                .render('charts/temp.html')
        )

    def gene_ph(self):
        (
            Line(  # 初始化配置
                init_opts=opts.InitOpts(
                    width='551px',
                    height='511px',
                    animation_opts=opts.AnimationOpts(animation=False))
            )
                .set_global_opts(  # 全局配置
                xaxis_opts=opts.AxisOpts(name='时间轴'),
                yaxis_opts=opts.AxisOpts(name='pH')
            )
                .add_xaxis(  # 添加x轴
                xaxis_data=list(self.ph.keys())[-10:]
            )
                .add_yaxis(  # 添加y轴
                series_name='氢离子浓度指数',
                y_axis=list(self.ph.values())[-10:],
                symbol='emptyCircle',
                is_smooth=True
            )
                .render('charts/pH.html')
        )

    def gene_tds(self):
        (
            Line(  # 初始化配置
                init_opts=opts.InitOpts(
                    width='551px',
                    height='511px',
                    animation_opts=opts.AnimationOpts(animation=False))
            )
                .set_global_opts(  # 全局配置
                xaxis_opts=opts.AxisOpts(name='时间轴'),
                yaxis_opts=opts.AxisOpts(name='ppm')
            )
                .add_xaxis(  # 添加x轴
                xaxis_data=list(self.tds.keys())[-10:]
            )
                .add_yaxis(  # 添加y轴
                series_name='总溶解固体',
                y_axis=list(self.tds.values())[-10:],
                symbol='emptyCircle',
                is_smooth=True
            )
                .render('charts/tds.html')
        )

    def gene_fish(self):
        (
            Line(  # 初始化配置
                init_opts=opts.InitOpts(
                    width='551px',
                    height='511px',
                    animation_opts=opts.AnimationOpts(animation=False))
            )
                .set_global_opts(  # 全局配置
                xaxis_opts=opts.AxisOpts(name='时间轴'),
                yaxis_opts=opts.AxisOpts(name='每公里密度')
            )
                .add_xaxis(  # 添加x轴
                xaxis_data=list(self.density_fish.keys())[-10:]
            )
                .add_yaxis(  # 添加y轴
                series_name='鱼群密度',
                y_axis=list(self.density_fish.values())[-10:],
                symbol='emptyCircle',
                is_smooth=True
            )
                .render('charts/fish.html')
        )

    def gene_boat(self):
        (
            Line(  # 初始化配置
                init_opts=opts.InitOpts(
                    width='551px',
                    height='511px',
                    animation_opts=opts.AnimationOpts(animation=False))
            )
                .set_global_opts(  # 全局配置
                xaxis_opts=opts.AxisOpts(name='时间轴'),
                yaxis_opts=opts.AxisOpts(name='每公里密度')
            )
                .add_xaxis(  # 添加x轴
                xaxis_data=list(self.density_ship.keys())[-10:]
            )
                .add_yaxis(  # 添加y轴
                series_name='船舶密度',
                y_axis=list(self.density_ship.values())[-10:],
                symbol='emptyCircle',
                is_smooth=True
            )
                .render('charts/boat.html')
        )
